- page_title    '新建项目'
- header_title  "项目", dashboard_projects_path

.project-edit-container
  .project-edit-errors
    = render 'projects/errors'
  .row.prepend-top-default
    .col-lg-3.profile-settings-sidebar
      %h4.prepend-top-0
        新建项目
      %p
        创建或者从其它流行的 Git 服务导入项目
    .col-lg-9
      = form_for @project, html: { class: 'new_project' } do |f|
        %fieldset.append-bottom-0
          .form-group.col-xs-12.col-sm-6
            = f.label :namespace_id, class: 'label-light' do
              %span
                项目路径
            .form-group
              .input-group
                - if current_user.can_select_namespace?
                  .input-group-addon
                    = root_url
                  = f.select :namespace_id, namespaces_options(params[:namespace_id] || :current_user, display_path: true), {}, {class: 'select2 js-select-namespace', tabindex: 1}

                - else
                  .input-group-addon.static-namespace
                    #{root_url}#{current_user.username}/
          .form-group.col-xs-12.col-sm-6.project-path
            = f.label :namespace_id, class: 'label-light' do
              %span
                项目名称
            = f.text_field :path, placeholder: "my-awesome-project", class: "form-control", tabindex: 2, autofocus: true, required: true
        - if current_user.can_create_group?
          .help-block
            Want to house several dependent projects under the same namespace?
            = link_to "创建群组", new_group_path

        - if import_sources_enabled?
          .project-import.js-toggle-container
            .form-group.clearfix
              = f.label :visibility_level, class: 'label-light' do
                导入项目
              .col-sm-12.import-buttons
                %div
                  - if github_import_enabled?
                    = link_to new_import_github_path, class: 'btn import_github' do
                      = icon 'github', text: 'GitHub'
                %div
                  - if bitbucket_import_enabled?
                    - if bitbucket_import_configured?
                      = link_to status_import_bitbucket_path, class: 'btn import_bitbucket', "data-no-turbolink" => "true" do
                        %i.fa.fa-bitbucket
                        Bitbucket
                    - else
                      = link_to status_import_bitbucket_path, class: 'how_to_import_link btn import_bitbucket', "data-no-turbolink" => "true" do
                        %i.fa.fa-bitbucket
                        Bitbucket
                      = render 'bitbucket_import_modal'
                %div
                  - if gitlab_import_enabled?
                    - if gitlab_import_configured?
                      = link_to status_import_gitlab_path, class: 'btn import_gitlab' do
                        %i.fa.fa-heart
                        GitLab.com
                    - else
                      = link_to status_import_gitlab_path, class: 'how_to_import_link btn import_gitlab' do
                        %i.fa.fa-heart
                        GitLab.com
                      = render 'gitlab_import_modal'
                %div
                  - if gitorious_import_enabled?
                    = link_to new_import_gitorious_path, class: 'btn import_gitorious' do
                      %i.icon-gitorious.icon-gitorious-small
                      Gitorious.org
                %div
                  - if google_code_import_enabled?
                    = link_to new_import_google_code_path, class: 'btn import_google_code' do
                      %i.fa.fa-google
                      Google Code
                %div
                  - if fogbugz_import_enabled?
                    = link_to new_import_fogbugz_path, class: 'btn import_fogbugz' do
                      %i.fa.fa-bug
                      Fogbugz
                %div
                  - if git_import_enabled?
                    = link_to "#", class: 'btn js-toggle-button import_git' do
                      %i.fa.fa-git
                      %span 其它仓库链接
                %div{ class: 'import_gitlab_project' }
                  - if gitlab_project_import_enabled? && current_user.is_admin?
                    = link_to new_import_gitlab_project_path, class: 'btn btn_import_gitlab_project project-submit' do
                      %i.fa.fa-gitlab
                      %span GitLab export

            .js-toggle-content.hide
              = render "shared/import_form", f: f

        .form-group
          = f.label :description, class: 'label-light' do
            Project description
            %span.light (optional)
          = f.text_area :description, placeholder: '说明格式',  class: "form-control", rows: 3, maxlength: 250

        .form-group.project-visibility-level-holder
          = f.label :visibility_level, class: 'label-light' do
            Visibility Level
            = link_to "(?)", help_page_path("public_access/public_access")
          = render('shared/visibility_radios', model_method: :visibility_level, form: f, selected_level: @project.visibility_level, form_model: @project)

        = f.submit '创建项目', class: "btn btn-create project-submit", tabindex: 4
        = link_to '取消', dashboard_projects_path, class: 'btn btn-cancel'

.save-project-loader.hide
  .center
    %h2
      %i.fa.fa-spinner.fa-spin
      正在创建项目 &amp; 版本库。
    %p 请稍候，页面会处理完成后自动刷新。

:javascript
  $('.how_to_import_link').bind('click', function (e) {
    e.preventDefault();
    var import_modal = $(this).next(".modal").show();
  });

  $('.modal-header .close').bind('click', function() {
    $(".modal").hide();
  });

  $('.btn_import_gitlab_project').bind('click', function() {
    var _href = $("a.btn_import_gitlab_project").attr("href");
    $(".btn_import_gitlab_project").attr("href", _href + '?namespace_id=' + $("#project_namespace_id").val() + '&path=' + $("#project_path").val());
  });

  $('.btn_import_gitlab_project').attr('disabled',true)
  $('.import_gitlab_project').attr('title', 'Project path and name required.');

  $('.import_gitlab_project').click(function( event ) {
    if($('.btn_import_gitlab_project').attr('disabled')) {
      event.preventDefault();
      new Flash("Please enter path and name for the project to be imported to.");
    }
  });

  $('#project_path').keyup(function(){
    if($(this).val().length !=0) {
      $('.btn_import_gitlab_project').attr('disabled', false);
      $('.import_gitlab_project').attr('title','');
      $(".flash-container").html("")
    } else {
      $('.btn_import_gitlab_project').attr('disabled',true);
      $('.import_gitlab_project').attr('title', 'Project path and name required.');
    }
  });

  $('.import_git').click(function( event ) {
    $projectImportUrl = $('#project_import_url')
    $projectImportUrl.attr('disabled', !$projectImportUrl.attr('disabled'))
  });